<?php

function store()
{
	//测试数组
	$a[0]["key1"]="value1";
	$a[0]["key2"]="value2";
	$a[1]["keyA"]="valueA";
	$b = null;//获取数组的key
	$c = null;//需要写入的字符
	$d = null;//数组长度

	foreach ($a as $k => $v) {

		
			$b = array_keys($v);
		
			$d = count($b);
			
			for ($i=0; $i <$d; $i++) { 
				if($i == $d-1){
				$c = $b[$i].'='.$v[$b[$i]].'\n';
				file_put_contents('text.txt',$c,FILE_APPEND);//如果是最后一个数组元素后面加/n
				}else{
					$c = $b[$i].'='.$v[$b[$i]].';';
				file_put_contents('text.txt',$c,FILE_APPEND);
				}
				
			}

		}

}
// store();//运行
load();

	
function load()
{

		$str = file_get_contents('text.txt');
		
		$str = mb_convert_encoding($str, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');
		$a = explode('\n',$str);
		$a = array_filter($a);//删除空数组
		$m=memory_get_usage(); 
		foreach ($a as $k => $v) {
			$a[$k] = explode(';',$v);
			$a[$k] = array_filter($a[$k]);//删除空数组
			// var_dump($a[$k]);
			
			foreach ($a[$k] as $key => $value) {

				$a[$k][$key] = explode('=',$value);
				$a[$k][$key] = array_filter($a[$k][$key]);//删除空数组
				if(count($a[$k][$key]) == 1){
					echo "string";

				}
				foreach ($a[$k][$key] as $keys => $values){
					if($keys%2==0){

						$a[$k][$values] = $a[$k][$key][$keys+1];
					} 
				}
				unset($a[$k][$key]);
				
				
			}
			
		}
		$n=memory_get_usage();
				echo $m-$n;die;
		 // var_dump($a);
}






?>
